<template>
<div class="tab-items" @click="tabClick">
    <div v-if="!isActive" >
      <slot name="tab-img"></slot>
    </div>
    <div v-else>
      <slot name="tab-img-active"></slot>
    </div>
    <!-- <div :class="{active: isActive}"> -->
    <div :style="activeStyles">
      <slot name="tab-text"></slot>
    </div>
</div>
 <!-- 最好上面的写法 因为替换相当于剪切 会把插槽中的属性也删掉
   <slot v-if="!isActive" name="tab-img"></slot>
    <slot v-else name="tab-img-active"></slot> 
    <slot :class="{active: isActive}" name="tab-text"></slot> -->


    <!--<div class="tab-items">
      <img src="../../assets/img/tabbar/home.svg" alt="">
      <div>首页</div>
      首页  这个单独站出来的首页用来查看这个组件中的父html元素
    </div>-->
    <!-- <div class="tab-items">分类</div>
    <div class="tab-items">购物车</div>
    <div class="tab-items">我的</div> -->

</template>

<script>
export default {
  name: 'TabBarItem',
  props:{
    // isActive: String,
    path: String,
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  data() {
    return {
      // isActive: true
    }
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1
    },
    activeStyles() {
      return this.isActive ? {color: this.activeColor} : {}
    }
  },
  methods: {
    tabClick() {
      this.$router.replace(this.path)
    }
  }
}
</script>

<style>
.tab-items {
    flex: 1;
    text-align: center;
    font-size: 14px;
  }
.tab-items img {
  height: 24px;
  width: 24px;
  margin-top: 3px;
  margin-bottom: 2px;
  vertical-align: middle;
}
.active {
  color: red;
}
</style>